package pri.ydy.eduService.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pri.ydy.commonUtils.R;
import pri.ydy.eduService.entity.EduCourse;
import pri.ydy.eduService.entity.EduTeacher;
import pri.ydy.eduService.service.EduCourseService;
import pri.ydy.eduService.service.EduTeacherService;

import java.util.List;
import java.util.Map;

/**
 * @Author: YeDongYong
 * @Date:2020/12/25
 * @Content:
 */
@RestController
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    //分页查询讲师
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable long page,@PathVariable long limit){
        Page<EduTeacher> pageteacher=new Page<>(page,limit);
        Map<String ,Object> map= teacherService.getTeacherFrontList(pageteacher);

        //返回当前页的所有数据
        return R.ok().data(map);
    }

    //讲师详情功能
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId){
        //1.根据讲师id查询讲师基本信息
        EduTeacher teacher = teacherService.getById(teacherId);
        //2.根据讲师id查询讲师课程
        QueryWrapper<EduCourse> wrapper=new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> courseList = courseService.list(wrapper);
        return R.ok().data("teacher",teacher).data("courseList",courseList);
    }

}
